{extend name='Common/index' /} {block name='content'}
<section class="content">
    <div class="box box-default">
        <div class="box-header with-border">
            <h3 class="box-title">{$info?'修改':'新增'}产品组</h3>
        </div>
        <div class="box-body">
            <div class="form">
                <div class="form-group">
                    <label for="name" class="col-sm-2 control-label">分组名称</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="name" name="name" placeholder="请输入分组名称" value="{$info?$info['name']:''}" autocomplete="off">
                        <input type="hidden" name="id" value="{$info?$info['id']:''}">
                    </div>
                </div>
                <div class="form-group form-class_id">
                  <label for="class_id" class="col-sm-2 control-label">所属分类</label>
                  <div class="col-sm-10">
                    <select name="class_id" id="class_id" class="form-control">
                      {if !empty($classlist)}
                      {foreach name="classlist" item="v"}
                      <option value="{$v.id}" {$info?$info['class_id']==$v['id']?'selected':'':''}>{$v.title}</option>
                      {/foreach}
                      {/if}
                    </select>
                  </div>
                </div>
                <div class="form-group">
                    <label for="slogan" class="col-sm-2 control-label">分组标语</label>
                    <div class="col-sm-10">
                        <textarea name="slogan" id="slogan" class="form-control" cols="30" rows="10" placeholder="请输入分组标语">{$info?$info['slogan']:''}</textarea>
                    </div>
                </div>
                <div class="form-group">
                    <label for="sort" class="col-sm-2 control-label">分组排序</label>
                    <div class="col-sm-10">
                        <input type="number" class="form-control" id="sort" name="sort" placeholder="请输入分组排序" value="{$info?$info['sort']:''}">
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">
                        <button type="button" class="btn btn-primary sub">提交</button>
                        <a href="javascript:history.go(-1);" class="btn btn-default">返回</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>
{/block} {block name='js'}
<script src="__STATIC__/dist/js/formBasic.js"></script>
<script>
    $('.sub').click(function() {
        let names = document.querySelectorAll('.form-group > div > [name]'),
            vals = {};
        names = [].slice.call(names);
        names.map((e) => {
            vals[e.name] = e.value;
        });
        ajax('{:url("admin/Product/addgroupAuth")}', vals, 'post').then(e => {
            if (e.status === 200) {
                alert(e.msg);
                location.href = "{:url('admin/Product/list')}";
            } else {
                alert(e.msg);
            }
        });
    });
</script>
{/block}